package com.autonavi.yunda.yunji.core.engine.script;

import com.autonavi.yunda.yunji.common.utils.clock.AmapClock;
import com.autonavi.yunda.yunji.core.engine.context.NodeGraph;
import com.autonavi.yunda.yunji.core.enums.EngineType;
import com.autonavi.yunda.yunji.core.vo.EngineData;
import com.autonavi.yunda.yunji.core.vo.EngineInterfaceConfigVO;
import com.autonavi.yunda.yunji.core.vo.ProjectExtraData;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

/**
 * @author cizhong.wcs
 * @date 2022/4/19 10:28
 */
public class InterfaceScriptClass extends BaseGroovyScriptClass {
    public Long interfaceId;
    public String projectId;
    public String uri;
    public EngineType engineType;
    public EngineData engineData;
    public NodeGraph nodeGraph;
    /**
     * 接口中所有节点方法和边中条件的class map
     */
    public Map<String, IFunctionScript> functionScriptClassMap = new HashMap<>();
    public ProjectExtraData projectExtraData;
    /**
     * 脚本数据库的更新时间
     */
    public Timestamp updateTime;
    /**
     * 该脚本实例创建时间
     */
    public String scriptCreateTime;
    public Boolean exposedByRestapi;


    public InterfaceScriptClass(String script, EngineInterfaceConfigVO interfaceConfig, EngineData engineData, ProjectExtraData projectExtraData) {
        super(script);
        this.interfaceId = interfaceConfig.getId();
        this.projectId = interfaceConfig.getProjectId();
        this.uri = interfaceConfig.getUri();
        this.engineType = interfaceConfig.getEngineType();
        this.engineData = engineData;
        this.nodeGraph = new NodeGraph(engineData);
        this.updateTime = interfaceConfig.getUpdateTime();
        this.scriptCreateTime = AmapClock.dateTimeStringFromTimestamp(AmapClock.now());
        this.projectExtraData = projectExtraData;
        this.exposedByRestapi = interfaceConfig.getExposedByRestapi();
    }

    public IFunctionScript getFunctionScriptClass(String funName) {
        return functionScriptClassMap.get(funName);
    }
}